Public Class PGBar
    Inherits System.ComponentModel.Component

#Region " Component Designer generated code "

    Public Sub New(Container As System.ComponentModel.IContainer)
        MyClass.New()

        'Required for Windows.Forms Class Composition Designer support
        Container.Add(me)
    End Sub

    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Component overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Component Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Component Designer
    'It can be modified using the Component Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
    End Sub

#End Region

    Public Function BuildProgressBar(ByVal strMessage As String, Optional ByVal strColor As String = "#C4CFE1", Optional ByVal intSpeed As Integer = 0, Optional ByVal intNbrOfBars As Integer = 0) As String
        Dim intNumberOfBars As Integer
        Dim i As Integer
        Dim BarSpeed As Integer
        Dim strTemp As String

        If intNbrOfBars = 0 Then
            intNumberOfBars = Len(strMessage) + 1
        Else
            intNumberOfBars = intNbrOfBars + 1
        End If


        If intSpeed = 0 Then BarSpeed = 1000
        If intSpeed = 1 Then BarSpeed = 100
        If intSpeed = 2 Then BarSpeed = 300
        If intSpeed = 3 Then BarSpeed = 500


        strColor = "#495571"

        strTemp = "<table border='0' height='98%' width='98%' id='mytable'><tr><td align='center' valign='middle'>"
        strTemp += "<table cellpadding='8px' bordercolor='" & strColor & "' border='1' style='display: None' cellpadding='0' cellspacing='1' align='center' id='pbar'><tr>"
        strTemp += "<td id='br0' style='FONT-WEIGHT: Normal; FONT-SIZE: 15px; COLOR: " & strColor & "; FONT-FAMILY: Arial, Helvetica, sans-serif'>"
        strTemp += "<div>" & strMessage & "</div><div><img src='images/blank.gif height='15px' width='3px'></div>"
        strTemp += "<table><tr>"
        For i = 1 To intNumberOfBars
            If i = 1 Then
                strTemp += "<td id='br" & i & "'" & " bgcolor='" & strColor & "' style='display: Block'><img src='images/blank.gif height='15px' width='3px'></td>"
            Else
                strTemp += "<td id='br" & i & "'" & " bgcolor='" & strColor & "' style='display: None'><img src='images/blank.gif height='15px' width='3px'></td>"
            End If
        Next i
        strTemp += "</tr></table>"
        strTemp += "</td></tr></table>"
        strTemp += "</td></tr></table>"
        strTemp += "<script language=javascript>var dots = 1;var dotmax = " & intNumberOfBars & ";"
        strTemp += "function ShowWait(){document.getElementById('pbar').style.display='block';dots++;if(dots>=dotmax){dots=2;resetprogressbar();}for(var x = 0;x < dots;x++){"
        strTemp += "document.getElementById('br' + (x)).style.display='block';}}"
        strTemp += "function StartShowWait(){window.setInterval('ShowWait()'," & BarSpeed & ");}"
        strTemp += "function HideWait(){document.getElementById('mytable').style.display='none';}"
        strTemp += "function resetprogressbar(){ for(var z=2;z<=" & intNumberOfBars & ";z++){document.getElementById('br' + (z)).style.display='none'}}"
        strTemp += "StartShowWait();</script>"

        Return strTemp
    End Function
End Class
